﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using ChatDAL;

namespace ChatService
{
    public class MessageDTO
    {
        public string Text { get; set; }
        public int ChannelID { get; set; }
        public string Posted { get; set; }

        public static MessageDTO ConvertFrom(Message message)
        {
            MessageDTO converted = new MessageDTO();
            converted.Text = message.Text;
            converted.ChannelID = message.ChannelID;
            converted.Posted = message.DateTimePosted.ToString();
            return converted;
        }

        public static MessageDTO[] ConvertAllFrom(Message[] messages)
        {
            MessageDTO[] converted = new MessageDTO[messages.Length];

            for (int i = 0; i < messages.Length; i++)
            {
                converted[i]=MessageDTO.ConvertFrom(messages[i]);
            }

            return converted;
        }

        public  Message ConvertToMessage()
        {
            Message message = new Message();
            message.ChannelID = this.ChannelID;
            message.Text = this.Text;
            message.DateTimePosted = DateTime.Now;

            return message;
        }
    }
}